﻿Imports Oracle.DataAccess.Client
Public Class fListaDtoRangoPrecios
    Dim lDtoRangoPrecio As String
    Public ReadOnly Property dtoRangoPrecio() As String
        Get
            Return lDtoRangoPrecio
        End Get
    End Property
    Private Sub btnConsulta_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsulta.Click
        Dim conn As OracleConnection = New OracleConnection(My.Settings.ConnectionString)
        Dim cmd As OracleCommand = conn.CreateCommand
        Dim CuentaW As Integer
        Dim CadSql As String = "SELECT * FROM GLO_DTORANGOPRECIOS "
        Dim qWhere As String = "WHERE "
        If txtValorDtoDesde.Text.Trim.Length > 0 Then
            CuentaW += 1
            qWhere &= "VALORDTO >=" & txtValorDtoDesde.Text & ""
        End If
        If txtValorDtoHasta.Text.Trim.Length > 0 Then
            If CuentaW > 0 Then _
                qWhere &= " AND "
            CuentaW += 1
            qWhere &= "VALORDTO <=" & txtValorDtoHasta.Text & ""
        End If
        If CuentaW > 0 Then _
            CadSql &= qWhere
        Try
            cmd.CommandText = CadSql
            conn.Open()
            DsGlobal.GLO_DTORANGOPRECIOS.Rows.Clear()
            DsGlobal.GLO_DTORANGOPRECIOS.Load(cmd.ExecuteReader)
            GLO_DTORANGOPRECIOSDataGridView.Focus()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        Finally
            conn.Close()
        End Try
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    Private Sub GLO_DTORANGOPRECIOSDataGridView_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles GLO_DTORANGOPRECIOSDataGridView.CellMouseDoubleClick
        If e.RowIndex >= 0 Then
            lDtoRangoPrecio = GLO_DTORANGOPRECIOSDataGridView.Rows(e.RowIndex).Cells("IDDTORANGOPRECIO").Value
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub

    Private Sub AsignaDtoRangoPrecios(ByVal Fila As Integer)
        If Fila >= 0 Then
            lDtoRangoPrecio = GLO_DTORANGOPRECIOSDataGridView.Rows(Fila).Cells("IDDTORANGOPRECIO").Value
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub


    Private Sub GLO_DTORANGOPRECIOSDataGridView_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles GLO_DTORANGOPRECIOSDataGridView.KeyDown
        If e.KeyData = Keys.Enter Then
            AsignaDtoRangoPrecios(GLO_DTORANGOPRECIOSDataGridView.CurrentRow.Index)
        End If
    End Sub
End Class